package dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import entity.ImageComment;

public class ImageCommentDao {

	private static ImageCommentDao instance;
	private BaseDao baseDao;

	protected ImageCommentDao() {
		this.baseDao = BaseDao.getInstance();
	}

	public static ImageCommentDao getInstance() {
		if (instance == null) {
			instance = new ImageCommentDao();
		}
		return instance;
	}
	
	public List<ImageComment> getListImageComment(String condition) throws Exception{
		String query = "SELECT * FROM image_comment";
		if(condition != null && !"".equals(condition)) {
			query = query + " " + condition;
		}
		ResultSet rs = baseDao.executeQuery(query);
		List<ImageComment> imageComments = new ArrayList<ImageComment>();
		while (rs.next()) {
			ImageComment object = new ImageComment(rs.getLong("ID"),
					rs.getString("COMMENT"),  
					rs.getInt("RATING"),
					rs.getString("CREATE_BY"),
					rs.getDate("CREATE_DATE"),
					rs.getString("MODIFY_BY"),
					rs.getDate("MODIFY_DATE"),
					rs.getInt("STATUS"));
			imageComments.add(object);
		}

		return imageComments;
	}
}
